<template>
    <div>
       <div class="layout-main">
            <el-form ref="merchant" label-position="right" label-width="120px" :model="merchant" :rules="rules">
                <el-form-item label="原登录密码" prop="oldpassport">
                    <el-row>
                        <el-col :span="8">
                            <el-input size="small" type="password" v-model="merchant.oldpassport" placeholder="原登录密码" style="width: 240px" />
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="新登录密码" type="password" prop="passport">
                    <el-row>
                        <el-col :span="8">
                            <el-input size="small" v-model="merchant.passport" placeholder="重复新密码" style="width: 240px" />
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="重复新密码" type="password" prop="cfgpassport">
                    <el-row>
                        <el-col :span="8">
                            <el-input size="small" v-model="merchant.cfgpassport" placeholder="重复新密码" style="width: 240px" />
                        </el-col>
                    </el-row>
                </el-form-item>
            </el-form>
            <div>
                <el-button size="small" @click="cancel">取消</el-button>
                <el-button size="small"  type="primary" :loading="modalLoading" @click="ok">确定</el-button>
            </div>
        </div>
    </div>
</template>
<script>
import api from '@/api/api';
export default {
    name: 'Merchant',
    data() {
        return {
            loading: false,
            modalLoading: false,

            others: {

            },
            merchant: {
                passport: '',
                oldpassport: '',
                cfgpassport: ''
            },
            rules: {
                passport: [
                    { required: true, message: "原登录密码不能为空", trigger: "blur" }
                ],
                oldpassport: [
                    { required: true, message: "新登录密码不能为空", trigger: "blur" }
                ],
                cfgpassport: [
                    { required: true, message: "重复登录密码不能为空", trigger: "blur" }
                ]
            },

        };
    },
    mounted: function() {



    },
    methods: {



        ok: function() {

            this.$refs['merchant'].validate((valid) => {

                if (valid) {
                    this.okSubmit();
                } else {
                    this.errorMessage('请认真填写数据');
                }
            })


        },
        okSubmit: function() {
            var me = this;

            me.modalLoading = true;
            me.$http.post("/sys/sysuser/dopwd.action", me.merchant).then(response => {
                var body = response;
                if (body.status == 0) {
                    me.successMessage("修改成功！正在重新登录");
                    me.modalEdit = false;
                    //
                    me.$store
                        .dispatch("loginOut")
                        .then(res => {

                            if (res.status == 0) {
                                me.$router.push("/login");
                            } else {
                                me.errorMessage(res.info);
                            }
                        }).catch(error => {

                        });

                } else {
                    me.errorMessage(body.info);
                }
                me.modalLoading = false;
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.$router.go(-1);
        }
    }
}
</script>
<style scoped>
</style>